package edu.pw.p2pclient.data;

import java.io.Serializable;

public class Resource extends Node implements Serializable {

	private static final long serialVersionUID = -2782348123893412639L;

	private boolean mIsBeingDownloaded;
	private int mBtSharedCount;
	private int mWifiSharedCount;

	public Resource(Node node) {
		super(node);
		mSharingInfo.mPassword = "";
		mIsBeingDownloaded = false;
		mBtSharedCount = node.isBtShared() ? 1 : 0;
		mWifiSharedCount = node.isWifiShared() ? 1 : 0;
	}

	public Resource(Resource resource) {
		super(resource);
		mIsBeingDownloaded = resource.mIsBeingDownloaded;
		mBtSharedCount = resource.mBtSharedCount;
		mWifiSharedCount = resource.mWifiSharedCount;
	}

	public boolean isBeingDownloaded() {
		return mIsBeingDownloaded;
	}

	public boolean isBtShared() {
		return mBtSharedCount > 0;
	}

	public boolean isWifiShared() {
		return mWifiSharedCount > 0;
	}

	public void increaseBtShared() {
		++mBtSharedCount;
	}

	public void decreaseBtShared() {
		--mBtSharedCount;
	}

	public void increaseWifiShared() {
		++mWifiSharedCount;
	}

	public void decreaseWifiShared() {
		--mWifiSharedCount;
	}

	public void setIsBeingDownloaded(boolean value) {
		mIsBeingDownloaded = value;
	}

	@Override
	public boolean equals(Object o) {

		if (o == null)
			return false;
		if (!(o instanceof Node))
			return false;
		Node tmp = (Node) o;
		return tmp.mName.equals(mName) && tmp.mSize == mSize;
	}

	@Override
	public int hashCode() {

		return mName.hashCode() + (int) mSize;
	}

}